package demo;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;

public class Folder {
    public static void main(String[] args) {
//        fileStatute(".");
//        String  ext="Folder.java.zip".substring("Folder.java.zip".lastIndexOf("."));
//        System.out.println(ext==".zip");
            fileFilterAction(".");

    }
    public static void fileStatute(String path){
        File file =new File(path);
        if (file.isDirectory()){
            File[]files=file.listFiles();
            for (File entry:files
                 ) {
                fileStatute(entry.getPath());
            }
        }else{
            if (file == null||file.length()<=0||!file.canRead()) {
                System.out.println(file.getName()+"文件为空或不可读");
                return;
            }
//            CopyDemo.zipFile(file.getPath(),file.getName()+".zip");

            if (file.getName().substring(file.getName().lastIndexOf(".")).equals(".zip")) {
                System.out.println(file.delete());
            }
        }
    }

    /**
     * 文件过滤
     * @param filepath 文件夹路径
     */
    public static void fileFilterAction(String filepath)  {
        if("".equals(filepath)||filepath==null){
            return;
        }
        File file=new File(filepath);
        if (file.isDirectory()) {
            FileFilter filter= file1 -> {
                fileFilterAction(file1.getPath());
                String name= file1.getName();
                return name.endsWith(".java");
            };
            File[]files=file.listFiles(filter);
            for (File entry:files
                 ) {
                System.out.println(entry.getName()+":"+entry.getParent()+":"+entry.length());
            }
        }
    }
}
